package com.zhoukx.netty.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 *
 *
 *   http开发模拟
 *
 */
public class TestServer {


    public static void main(String[] args) {
        // 创建两个线程组  一个是bossGroup 一个是workGroup
        NioEventLoopGroup bossgroup = new NioEventLoopGroup();

        NioEventLoopGroup workgroup = new NioEventLoopGroup();

        try {


        // 创建服务启动对象
        ServerBootstrap serverBootstrap = new ServerBootstrap();

        // 把线程组 放到启动环境中并且指定 handler
        serverBootstrap.group(bossgroup,workgroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new  TestServerInitializer());


        // 监听端口并且说明是非阻塞
        ChannelFuture ct = serverBootstrap.bind(6668).sync();

        ct.channel().closeFuture().sync();

        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            bossgroup.shutdownGracefully();
            workgroup.shutdownGracefully();
        }
    }
}
